<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <link rel="stylesheet" href="css/reset.css" type="text/css" />
	<link rel="stylesheet" href="css/common.css" type="text/css" />
	<link rel="stylesheet" href="css/sign-up.css" type="text/css" />
	<script src="scripts/jquery-1.5.2.min.js"></script>
	<script src="scripts/common.js"></script>
        <script type="text/javascript">
			$(document).ready(function(){
				$("#tbusername").bind("keyup", function()
				{
					var Username = $("#tbusername").attr("value");
					if(Username != "")
					{
						var serverURL = "BUS/xl_TaiKhoan.php?Username=" + Username;
						ValidateUsername();
						$("#erroruser").load(serverURL);
					}
					else
					{
						$("#erroruser").html("");
					}
				});
				
				$("#tbpassword").bind("keyup", function()
				{
					var password = $("#tbpassword").attr("value");
					if(password == "")
					{
						$("#erroremptypassword").attr("style", "visibility:visible");
					}
					else
					{
						$("#erroremptypassword").attr("style", "visibility:hidden");
					}
				});
				
				$("#tbpassword").bind("focus", function()
				{
					ValidateUsername();
				});
				$("#tbrepassword").bind("focus", function()
				{
					ValidateUsername();
				});
				$("#tbfullname").bind("focus", function()
				{
					ValidateUsername();
					ValidatePassword();
				});
				$("#tbemail").bind("focus", function()
				{
					ValidateUsername();
					ValidatePassword();
				});
				$("#tbaddress").bind("focus", function()
				{
					ValidateUsername();
					ValidatePassword();
					ValidateEmail();
				});
				$("#tbphone").bind("focus", function()
				{
					ValidateUsername();
					ValidatePassword();
					ValidateEmail();
				});
				
				$("#tbrepassword").bind("keyup", function()
				{
					ValidatePassword();
				});
				$("#tbemail").bind("keyup", function()
				{
					ValidateEmail();
				});
				
				$("#tbrepassword").bind("focus", function()
				{
					var Password = $("#tbpassword").attr("value");
					if(Password == "")
					{
						$("#erroremptypassword").attr("style", "visibility:visible");
					}
				});
				$("#tbpassword").bind("focus", function()
				{
					var Username = $("#tbusername").attr("value");
					if(Username == "")
					{
						$("#erroremptyuser").attr("style", "visibility:visible");
					}
				});
				$("#tbpassword").bind("focus", function()
				{
					var Username = $("#tbusername").attr("value");
					if(Username == "")
					{
						$("#erroremptyuser").attr("style", "visibility:visible");
					}
				});
				
				//$("#imgrefresh").bind("click", function()
				//{
				//	var serverURL = "BUS/Captcha.php";
				//	$("#imgcapcha").load(serverURL);
				//});
				
				function ValidateUsername()
				{
					var Username = $("#tbusername").attr("value");
					if(Username == "")
					{
						$("#erroremptyuser").attr("style", "visibility:visible");
						$("#erroruser").html("");
					}
					else
					{
						$("#erroremptyuser").attr("style", "visibility:hidden");
					}
				}
				
				function ValidatePassword()
				{
					var Password = $("#tbpassword").attr("value");
					if(Password == "")
					{
						$("#erroremptypassword").attr("style", "visibility:visible");
					}
					else
					{
						var password = $("#tbpassword").attr("value");
						var repassword = $("#tbrepassword").attr("value");
						if(password != repassword)
						{
							$("#errorrepassword").attr("style", "visibility:visible");
							$("#erroremptyrepassword").attr("style", "visibility:hidden");
							return 0;
						}
						else
						{
							$("#errorpassword").attr("style", "visibility:hidden");
							$("#errorrepassword").attr("style", "visibility:hidden");
							$("#erroremptyrepassword").attr("style", "visibility:hidden");
							return 1;
						}
						if(repassword == "")
						{
							$("#errorrepassword").attr("style", "visibility:hidden");
							$("#erroremptyrepassword").attr("style", "visibility:visible");
							return 0;
						}
					}
				}
				
				function ValidateEmail()
				{
					var Email = $("#tbemail").attr("value");
					if(Email != "")
					{
						$("#erroremptyemail").attr("style", "visibility:hidden");
						return 1;
					}
					else
					{
						$("#erroremptyemail").attr("style", "visibility:visible");
						return 0;
					}
				}
				
				$("#btregistry").bind("click", function()
				{
					$("#erroremptyuser").attr("style", "visibility:hidden");
					$("#erroremptyuser").attr("style", "visibility:hidden");
					var count = 0;
					var temp = 0;
					
					
					if(ValidatePassword())
					{
						count++;
					}
					if( ValidateEmail())
					{
						count++;
					}
					if($("#usernamevalid").length > 0)
					{
						count++;
					}
					else
					{
						temp = 1;
					}
					if(count != 3)
					{
						if(temp == 1)
						{
							$("#erroruser").html("<label style='color:#F00' id='usernamevalid' class='error'>Chưa điền tên đăng nhập !</label>");
							return false;
						}
						return false;
					}
					
				});
			});
			var xmlhttp;

				function GetXmlHttpObject()
				{
					if (window.XMLHttpRequest)
					{
						// code for IE7+, Firefox, Chrome, Opera, Safari
						return new XMLHttpRequest();
					}
					if (window.ActiveXObject)
					{
						// code for IE6, IE5
						return new ActiveXObject("Microsoft.XMLHTTP");
					}
					return null;
				}
				
				function ChangeCaptCha()
				{
					alert(1);
					xmlhttp = GetXmlHttpObject();
					if(xmlhttp == null)
					{
						alert("Browser do not support HTTP REQUEST");
						return;
					}
					var url = "BUS/Captcha.php";
					xmlhttp.onreadystatechange=ChangeCaptCha_Change;
					xmlhttp.open("GET",url,true);
					xmlhttp.send("null");
				}
				
				function ChangeCaptCha_Change()
				{
					if (xmlhttp.readyState==4)
					{
						document.getElementById("imgcaptcha").src = xmlhttp.responseText;
					}
				}
		</script>
</head>

<body>
    <div id="page">
        <?php
			require("config.php");
            require("UserControl/header.php");
        ?>
        <?php
			require("DAO/DataHelper.php");
			if(isset($_REQUEST["Registry"]))
			{
				echo "thành công";
				Gotopage("temp/sign-up2.html");
			}
		?>
       <div id="content">
            <div id="sign-up" class="block layout-1col">
                <div class="title"><h4>Đăng ký</h4></div>
                <ul class="content">
                    <form action="DangKy.php" method="post">
                        <div class="first">
                            <h6>Loại người dùng</h6>
                            <label for="su-type">Bạn là?</label>
                            <select id="su-type">
                                <option value="buyer">Người mua</option>
                                <option value="seller">Người bán</option>
                            </select>
                        </div>
                        <div>
                            <h6>Thông tin đăng nhập</h6>
                            <label for="su-username">Tên đăng nhập</label>
                            <input type="text" id="tbusername" class="tb" />
                            
                            <div id="erroruser"></div>
                            <span style="visibility:hidden" id="erroremptyuser" class="error">Chưa điền tên đăng nhập !</span>
                            <label for="su-password">Mật khẩu</label>
                            <input type="password" id="tbpassword" class="tb" />
                            <span class="error" id="erroremptypassword" style="visibility:hidden">Chưa điền password !</span>
                            <label for="su-repassword">Nhập lại mật khẩu</label>
                            <input type="password" id="tbrepassword" class="tb" />
                            <span class="error" id="errorrepassword" style="visibility:hidden">Mật khẩu không đúng</span>
                            <span class="error" id="erroremptyrepassword" style="visibility:hidden">Vui lòng xác nhận lại mật khẩu</span>
                        </div>
                        <div class="last">
                            <h6>Thông tin cá nhân</h6>
                            <label for="su-fullname">Họ tên</label>
                            <input type="text" id="tbfullname" class="tb" />
                            <label for="su-email">Email</label>
                            <input type="text" id="tbemail" class="tb" />
                            <span class="error" id="erroremptyemail" style="visibility:hidden">Chưa điền email !</span>
                            <span class="error" id="erroremail" style="visibility:hidden">Email không hợp lệ!</span>
                            <label for="su-sex">Giới tính</label>
                            <select id="su-sex">
                                <option value="male">Nam</option>
                                <option value="female">Nữ</option>
                            </select>
                            <label for="su-address">Địa chỉ</label>
                            <input type="text" id="tbaddress" class="tb" />
                            <label for="su-phone">Điện thoại</label>
                            <input type="text" id="tbphone" class="tb" />
                            <label for="su-avatar">Ảnh đại diện</label>
                            <input type="file" id="su-avatar" class="tb" />
                            <span class="guide">Nếu bạn không chọn ảnh đại diện, website sẽ chọn ảnh mặc định<br />Chỉ chấp nhận định dạng jpg, png, gif và không vượt quá 60x60px</span>
                            <span class="error">Chỉ cho phép jpg, png, gif!</span>
                            <span class="error">Ảnh không được vượt quá 60x60px!</span>
                            
                            Nhập chuỗi xác nhận <input type="text" name="captchaimg" />
                			<img src="BUS/Captcha.php" width="50" height="24" id="imgcaptcha" />
                            <img src="<?php print $root ?>/images/Button-Refresh-icon.png" style="cursor:pointer" onclick="ChangeCaptCha()" />
                            <input type="submit" class="btn pre-submit" name="Registry" id="btregistry" value="Đăng ký" />
                            
                        </div>							
                    </form>
                </ul>
            </div>				
        </div>
        <?php
            require("UserControl/Footer.php");
        ?>
     </div>
</body>
</html>